home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / newmat03.lha / newmat03 / controlw.hxx < prev    next >
Text File  |  1993-08-08  |  2KB  |  48 lines

  1. //$$ controlw.hxx              Control word class
  2.  
  3. #ifndef CONTROL_WORD_LIB
  4. #define CONTROL_WORD_LIB 0
  5.  
  6. // for organising an int as a series of bits which indicate whether an
  7. // option is on or off.
  8.  
  9. class ControlWord
  10. {
  11.    unsigned int cw;                             // the control word
  12. public:
  13.    ControlWord() {}                             // do nothing
  14.    ControlWord(unsigned int i) : cw(i) {}       // load an integer
  15.  
  16.       // select specific bits (for testing at least one set)
  17.    ControlWord operator*(ControlWord i)  { return cw & i.cw; }
  18.    ControlWord operator*(unsigned int i) { return cw & i; }
  19.  
  20.       // set bits
  21.    ControlWord operator+(ControlWord i)  { return cw | i.cw; }
  22.    ControlWord operator+(unsigned int i) { return cw | i; }
  23.    void operator+=(ControlWord i)  { cw |= i.cw; }
  24.    void operator+=(unsigned int i) { cw |= i; }
  25.  
  26.       // reset bits
  27.    ControlWord operator-(ControlWord i)  { return cw - (cw & i.cw); }
  28.    ControlWord operator-(unsigned int i) { return cw - (cw & i); }
  29.    void operator-=(ControlWord i)  { cw -= (cw & i.cw); }
  30.    void operator-=(unsigned int i) { cw -= (cw & i); }
  31.  
  32.       // check if all of selected bits set or reset
  33.    BOOL operator>=(ControlWord i)  { return (cw & i.cw) == i.cw; }
  34.    BOOL operator>=(unsigned int i) { return (cw & i) == i; }
  35.    BOOL operator<=(ControlWord i)  { return (cw & i.cw) == cw; }
  36.    BOOL operator<=(unsigned int i) { return (cw & i) == cw; }
  37.  
  38.       // flip selected bits
  39.    ControlWord operator^(ControlWord i)  { return cw ^ i.cw; }
  40.    ControlWord operator^(unsigned int i) { return cw ^ i; }
  41.    ControlWord operator~() { return ~cw; }
  42.  
  43.    operator int() { return cw; }
  44. };
  45.  
  46.  
  47. #endif
  48.